import java.util.Scanner;

/**
 * @author vivi
 * @description
 * @date 2024/5/13
 */
public class demo1 {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] arr = scanner.next().toCharArray();

        int ret = -1;
        int len = arr.length;

        for (int i = 0; i < len; i++) {
            if (i+1 < len && arr[i] == arr[i+1]){
                ret = 2;
                break;
            }
            if (i+2 < len && arr[i] == arr[i+2]){
                ret = 3;
            }
        }

        System.out.println(ret);
    }
}
